﻿@{
    Layout = null;
}
<script src="~/Scripts/jquery-3.4.1.min.js"></script>
<link href="~/Content/bootstrap.css" rel="stylesheet" />
<link href="~/layer/skin/layer.css" rel="stylesheet" />
<script src="~/layui/layui.js"></script>

<h3 style="text-align:center">修改物资采购</h3>
<table style="text-align:center" align="center">
    <tr>
        <td>物资名称：</td>
        <td><input id="name" /><span id="sname" style="color:red">*</span></td>
    </tr>
    <tr>
        <td>类&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;型：</td>
        <td>
            <select style="width:205px" id="typeName">
                <option>请选择</option>
            </select>
        </td>
    </tr>
    <tr>
        <td>材&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;质；</td>
        <td><input id="material" /></td>
    </tr>
    <tr>
        <td>规&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;格：</td>
        <td><input id="specifications" /><span id="sspecifications" style="color:red">*</span></td>
    </tr>
    <tr>
        <td>产&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;地：</td>
        <td><input id="origin" /><span id="sorigin" style="color:red">*</span></td>
    </tr>
    <tr>
        <td>数&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;量：</td>
        <td><input id="num" type="number" /><span id="snum" style="color:red">*</span></td>
    </tr>
    <tr>
        <td>用途描述：</td>
        <td><input id="describe" /><span id="sdescribe" style="color:red">*</span></td>
    </tr>
    <tr>
        <td>申&nbsp;&nbsp;请&nbsp;&nbsp;人：</td>
        <td><input id="applicant" /><span id="sapplicant" style="color:red">*</span></td>
    </tr>
    <tr>
        <td>备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注：</td>
        <td><input id="remarks" /><span id="sremarks" style="color:red">*</span></td>
    </tr>
    <tr>
        <td>审批状态：</td>
        <td><input type="radio" name="state" value="1">已送达</input><input type="radio" name="state" value="3" checked>等待中</input><input type="radio" name="state" value="2">运送中</input></td>
    </tr>
    <tr>
        <td>审&nbsp;&nbsp;批&nbsp;&nbsp;人：</td>
        <td><input id="userId" /><span id="suserId" style="color:red">*</span></td>
    </tr>
    <tr>
        <td colspan="2"><button onclick="UpdateProc()">修改</button></td>
    </tr>
</table>
<script>
        function Material(){
            $.ajax({
                url:"/Approve/GetMaterial",
                type:"get",
                dataType:"json",
                success:function(obj){
                    console.info(obj)
                    $(obj).each(function(){
                        $("#typeName").append("<option value="+this.id+">"+this.name+"</option>")
                    })
                }
            })
        }
        function PutAsyncc(){
            $.ajax({
                url: "/Approve/GetAsyncc?id=" + @ViewBag.id,
                type: "get",
                dataType: "json",
                success: function (obj) {
                    console.info(obj)
                    $("#name").val(obj.name)
                    $("#typeName").val(obj.procurementTypeId)
                    $("#material").val(obj.material)
                    $("#specifications").val(obj.specifications)
                    $("#origin").val(obj.origin)
                    $("#num").val(obj.num)
                    $("#describe").val(obj.describe)
                    $("#applicant").val(obj.applicant)
                    $("#remarks").val(obj.remarks)
                    $("[name=state][value="+obj.state+"]").prop("checked",true)
                    $("#userId").val(obj.userId)
                }
            })
        }
        $(function () {
            Material()
            PutAsyncc()
        })

    function fh(){
        window.parent.location.reload();
        var index = parent.layer.getFrameIndex(window.name);parent.layer.close(index);
    }
        function UpdateProc() {
            if ($("#name").val() == "") {
                $("#sname").html("物资名称不能为空！")
                return;
            }if ($("#name").val() != "") {
                $("#sname").html("*")
            }
            if ($("#specifications").val() == "") {
                $("#sspecifications").html("规格不能为空！")
                return;
            }if ($("#specifications").val() != "") {
                $("#sspecifications").html("*")
            }
            if ($("#origin").val() == "") {
                $("#sorigin").html("产地不能为空！")
                return;
            }if ($("#origin").val() != "") {
                $("#sorigin").html("*")
            }
            if ($("#num").val() <=-1) {
                $("#snum").html("数量不能小于0！")
                return;
            }if ($("#num").val() >=0 ) {
                $("#snum").html("*")
            }
            if ($("#applicant").val() == "") {
                $("#sapplicant").html("申请人不能为空！")
                return;
            }if ($("#applicant").val() != "") {
                $("#sapplicant").html("*")
            }
            var formData=new FormData();
                formData.append("Id",@ViewBag.id);
                formData.append("Name",$("#name").val());
                formData.append("ProcurementTypeId",$("#typeName").val());
                formData.append("Material",$("#material").val());
                formData.append("Specifications",$("#specifications").val());
                formData.append("Origin",$("#origin").val());
                formData.append("Num",$("#num").val());
                formData.append("Describe",$("#describe").val());
                formData.append("Remarks",$("#remarks").val());
                formData.append("State",$("[name=state]:checked").val());
                formData.append("UserId",$("#userId").val());
                formData.append("Applicant",$("#applicant").val());
            $.ajax({
                url: "/Approve/Updates",
                type: "put",
                dataType: "json",
                data:formData,
                cache:false,
                contentType: false,
                processData: false,
                success: function (obj) {
                    if (obj > 0) {
                        alert("修改成功");
                        fh();
                        location.href="/Approve/ApproveIndex"
                    }
                    else {
                        layer.msg("修改失败")
                    }
                }
            })
        }
</script>